﻿using System.Linq;
using WholesaleOnline.Model;

namespace WholesaleOnline.WebUI.Common
{
    public static class GoodsExtension
    {
        public static dynamic ConvertToInventoryGoodsJsonModel(this WoProduct product)
        {
            return new
            {
                id = product.Id,
                name = product.Name,
                fullPrice = string.Format("{0}/{1}", product.Price, product.Unit.Name),
                unit = product.Unit.Name,
                pic = product.Img,
                seller = product.Seller.Name,
                sn = product.Sn,
                desc = product.Description,
                bigUnits = product.BigUnits.Select(u => new
                {
                    id = u.Unit.Id,
                    name = u.Unit.Name,
                    count = u.Count
                })
            };
        }
    }
}